package com.woniuxy.tools.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.woniuxy.entity.ShopOrder;
import com.woniuxy.service.OrderService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author hq
 * @Date 2025/7/22$ 18:36$
 * @Description TODO
 * @Params $
 * @Return $
 **/
@Service
public class OrderToolService {
    @Autowired
    private OrderService orderService;

    @Tool(description = "查询我的订单列表")
    public String getMyOrderList(Integer userId) {
        List<ShopOrder> orderList = orderService.getMyOrderList(userId);
        ObjectMapper mapper = new ObjectMapper();
        String json = null;
        try {
            json = mapper.writeValueAsString(orderList);
        } catch (Exception e) {
            return "没有找到订单";
        }
        return json;
    }

    @Tool(description = "根据订单编号orderId查询订单详情")
    public String getOrderDetail(String orderId) {
        ShopOrder order = orderService.getOrderById(orderId);
        ObjectMapper mapper = new ObjectMapper();
        String json = null;
        try {
            json = mapper.writeValueAsString(order);
        } catch (Exception e) {
            return "没有找到订单";
        }
        return json;
    }
    @Tool(description = "删除订单")
    public String deleteOrder(String orderId) {
        boolean success = orderService.deleteOrder(orderId);
        if (success) {
            return "订单删除成功";
        } else {
            return "订单删除失败";
        }
    }
}
